/**
 * 日期格式化
 * @param {String} time 
 * @return
 */

function dateD(time){
    var d_minutes,d_hours,d_days,d;
    var nowTime=parseInt(new Date().getTime()/1000);
    newTime=new Date(time).getTime()/1000;
    d=newTime-nowTime;
    d_days = parseInt(d/86400);       
    d_hours = parseInt(d/3600);       
    d_minutes = parseInt(d/60); 
    if(d_days>0){
        return d_days+'天前'
    }else if(d_days<=0&&d_hours>0){
        return d_hours+'小时前';
    }else if(d_hours<=0 && d_minutes>0){       
        return d_minutes+"分钟前";
    }else{
        return '刚刚'
    }
}



/**
 * 判断浏览器内核
 * @returns
 */
function liulanqi() {
    var u = navigator.userAgent;
    return {
            trident: u.indexOf('Trident') > -1, //IE内核
            presto: u.indexOf('Presto') > -1, //opera内核
            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
            gecko: u.indexOf('Firefox') > -1, //火狐内核Gecko
            mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android
            iPhone: u.indexOf('iPhone') > -1 , //iPhone
            iPad: u.indexOf('iPad') > -1, //iPad
            webApp: u.indexOf('Safari') > -1 //Safari
        }
    }



/**
 * 判断是否是移动端
 */
var browser = {
  versions: function() {
    var u = navigator.userAgent;
    return {
            mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android
            iPhone: u.indexOf('iPhone') > -1 , //iPhone
            iPad: u.indexOf('iPad') > -1, //iPad
            webApp: u.indexOf('Safari') > -1 //Safari
        };
    }
}
if (browser.versions.mobile || browser.versions.ios || browser.versions.android || browser.versions.iPhone || browser.versions.iPad) {
    alert('移动端');
}else(
    alert('PC')
)


/**
 * COOKIE存储
 * @param {String} key 
 * @param {Object} val 
 * @param {Number} time 
 */
function setcookie(key, val, time=10) {
    if(typeof val == 'object') val = JSON.stringify(val)

    const d = new Date
    d.setTime(d.getTime() - 1000*60*60*8 + 1000*time)
    document.cookie = `${key}=${val}; expires`
}


/**
 * COOKIE获取
 * @param {String} key 
 */
function getcookie(key) {
    let arr = document.cookie.split('; ')
    for (let i=0; i<arr.length; i++) {
        let item = arr[i]
        let tempArr = item.split('=')
        if (tempArr[0] == key) return tempArr[1]
    }
}


/**
 * COOKIE删除
 * @param {String} key 
 */
function removecookie(key) {
    setcookie(key, null, -1)
}


/**
 * 获取地址栏参数
 * @param {*} key 
 */
function getParams(key){
    let query = window.location.search.substring(1)
    query = decodeURI(query)
    let arr = query
    for(let i=0;i<arr.length;i++){
        let temp = arr[i].split('=')
        if(temp[0] == key) return temp[1]
    }
    return false
}
console.log(getParams('uname'))